package com.java.yz.day10.ketang;

/*
    String和StringBuffer的相互转换

    把数组拼接成一个字符串

    把字符串反转

    判断一个字符串是否是对称字符串
    例如"abc"不是对称字符串，"aba"、"abba"、"aaa"、"mnanm"是对称字符串
 */
public class StringBufferText1 {
    public static void main(String[] args) {
        //String和StringBuffer的相互转换
        StringBuffer stringBuffer1 = new StringBuffer("你好");  //String -> StringBuffer
        System.out.println(stringBuffer1);
        System.out.println(stringBuffer1.toString());  //String <- StringBuffer

        //把数组拼接成一个字符串
        int[] ints={1,2,3,4};
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < ints.length; i++) {
            stringBuffer.append(ints[i]);
        }
        System.out.println(stringBuffer);

        //把字符串反转
        StringBuffer stringBuffer2 = new StringBuffer("顾文泽");
        stringBuffer2.reverse();
        System.out.println(stringBuffer2);

        //判断一个字符串是否是对称字符串
        //例如"abc"不是对称字符串，"aba"、"abba"、"aaa"、"mnanm"是对称字符串

        StringBuffer stringBuffer3 = new StringBuffer("abc");
        String s1=stringBuffer3.toString();
        StringBuffer stringBuffer4=stringBuffer3.reverse();
        String s2=stringBuffer4.toString();
        if (s1.equals(s2)){
            System.out.println("是对称");
        }else {
            System.out.println("不是对称");
        }

    }
}
